﻿using AutoMapper;
using MyCompany.MyProject.Common;
using MyCompany.MyProject.IService;
using MyCompany.MyProject.Model.Models;
using MyCompany.MyProject.Repository.Base;

namespace MyCompany.MyProject.Service
{
    public class DepartmentServices : BaseService<Department>, IDepartmentService
    {
        private readonly IBaseRepository<Department> baseRepository;

        public DepartmentServices(/*IMapper mapper,*/ IBaseRepository<Department> baseRepository) : base(baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        [UseTran(Propagation = Propagation.Required)]
        public async Task<bool> TestTranPropagation()
        {
            TimeSpan timeSpan = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var id = timeSpan.TotalSeconds.ObjToLong();
            var insertObj = await baseRepository.Add(new Department()
            {
                Id = id,
                Name = $"department name {id}",
                CodeRelationship = "",
                OrderSort = 0,
                Status = true,
                IsDeleted = false,
                Pid = 0,
            });

            await Console.Out.WriteLineAsync($"db context id :{base.Db.ContextID}");
            return true;
        }
    }
}
